package com.frank.im.db;

import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.frank.im.base.ImChatManage;
import com.frank.im.bean.HistorySession;
import com.frank.im.bean.MsgCont;
import com.frank.im.bean.MsgContExp;
import com.frank.im.bean.SessionRecord;
import com.frank.im.bean.SysMsg;
import com.frank.im.bean.SysMsgCont;
import com.frank.im.bean.UserChatMsg;
import com.frank.im.bean.UserTemp;

/**
 * im通讯数据访问接口实现
 * 
 * @author Frank
 * @version 1.0 Create by 2016.4.11
 */
public class ImDaoImpl implements ImDao {

	private static ImDaoImpl dbMgr = new ImDaoImpl();
	private DBHepler dbHepler;

	@Override
	public synchronized void onInit(Context context) {
		dbHepler = DBHepler.getInstance(context);
	}

	public synchronized static ImDaoImpl getInstance() {
		return dbMgr;
	}

	@Override
	public synchronized boolean isExists(int type, String... id) {
		boolean exists = false;
		SQLiteDatabase db = dbHepler.getReadableDatabase();
		if (db.isOpen()) {
			String selection = "";
			String[] selectionArgs = id;
			Cursor cursor = null;
			switch (type) {
			case 1:
				selection = UserTemp.USER_ID + "=?";
				cursor = db.query(UserTemp.TABLENMAE, null, selection,
						selectionArgs, null, null, null);
				exists = (cursor.getCount() > 0) ? true : false;
				break;
			case 2:
				selection = SessionRecord.USER_ID + "=?";
				cursor = db.query(SessionRecord.TABLENMAE, null, selection,
						selectionArgs, null, null, null);
				exists = (cursor.getCount() > 0) ? true : false;
				break;
			case 3:
				selection = MsgCont.SERVICE_CONT_ID + "=?";
				cursor = db.query(MsgCont.TABLENMAE, null, selection,
						selectionArgs, null, null, null);
				exists = (cursor.getCount() > 0) ? true : false;
				break;
			case 4:
				selection = MsgCont.REQUEST_ID + "=?";
				cursor = db.query(MsgCont.TABLENMAE, null, selection,
						selectionArgs, null, null, null);
				exists = (cursor.getCount() > 0) ? true : false;
				break;
			case 5:
				selection = SysMsgCont.SERVICE_CONT_ID + "=?";
				cursor = db.query(SysMsgCont.TABLENMAE, null, selection,
						selectionArgs, null, null, null);
				exists = (cursor.getCount() > 0) ? true : false;
				break;

			default:
				break;
			}

			if (cursor != null) {
				cursor.close();
			}
		}
		return exists;
	}

	/**
	 * 删除
	 */
	@Override
	public synchronized boolean del(int tableType, int operateType,
			String... id) {
		int delNum = -1;
		SQLiteDatabase db = dbHepler.getWritableDatabase();
		if (db.isOpen()) {
			String whereClausePath = "";
			String[] whereArgsPath = id;
			switch (tableType) {
			case 1:
				if (operateType == 1) {
					try {
						db.beginTransaction();
						whereClausePath = SessionRecord.USER_ID + "=?";
						delNum = db.delete(SessionRecord.TABLENMAE,
								whereClausePath, whereArgsPath);
						if (id.length > 0 && delNum != -1) {
							String userId = id[0];
							if (userId.equals("0")) {
								delNum = db.delete(SysMsgCont.TABLENMAE, null,
										null);
							} else {
								whereClausePath = MsgCont.FROM_ID + "=? or "
										+ MsgCont.TO_ID + "=?";
								whereArgsPath = new String[] { id[0], id[0] };
								delNum = db.delete(MsgCont.TABLENMAE,
										whereClausePath, whereArgsPath);
								if (delNum != -1) {
									whereClausePath = MsgContExp.FROM_ID
											+ "=? or " + MsgContExp.TO_ID
											+ "=?";
									delNum = db.delete(MsgContExp.TABLENMAE,
											whereClausePath, whereArgsPath);
								}
							}
						}
						db.setTransactionSuccessful();
					} catch (Exception e) {
						e.printStackTrace();
					} finally {
						db.endTransaction();
					}

				} else if (operateType == 2) {
					try {
						db.beginTransaction();
						delNum = db.delete(SessionRecord.TABLENMAE, null, null);
						delNum = db.delete(SysMsgCont.TABLENMAE, null, null);
						delNum = db.delete(MsgCont.TABLENMAE, null, null);
						delNum = db.delete(MsgContExp.TABLENMAE, null, null);
						db.setTransactionSuccessful();
					} catch (Exception e) {
						e.printStackTrace();
					} finally {
						db.endTransaction();
					}

				}

				break;
			case 2:
				if (operateType == 1) {
					delNum = db.delete(MsgCont.TABLENMAE, whereClausePath,
							whereArgsPath);
				} else if (operateType == 2) {
					delNum = db.delete(MsgCont.TABLENMAE, null, null);
				}
				break;

			default:
				break;
			}
		}
		return delNum == -1 ? false : true;
	}

	@Override
	public synchronized long insertUserTemp(UserTemp userTemp) {
		int number = 0;
		SQLiteDatabase db = dbHepler.getWritableDatabase();
		if (db.isOpen()) {
			ContentValues userCv = new ContentValues();
			userCv.put(UserTemp.USER_ID, userTemp.userId);
			userCv.put(UserTemp.USER_NAME, userTemp.userName);
			userCv.put(UserTemp.HEAD_IMG, userTemp.headImg);
			number = (int) db.insert(UserTemp.TABLENMAE, null, userCv);
		}
		return number;
	}

	@Override
	public synchronized long insertSessionRecord(SessionRecord sessionRecord) {
		int number = 0;
		SQLiteDatabase db = dbHepler.getWritableDatabase();
		if (db.isOpen()) {
			ContentValues sessionRecordCv = new ContentValues();
			sessionRecordCv.put(SessionRecord.USER_ID, sessionRecord.userId);
			sessionRecordCv.put(SessionRecord.NEW_CONT, sessionRecord.newCont);
			sessionRecordCv.put(SessionRecord.NEW_CONT_TIME,
					sessionRecord.newContTime);
			sessionRecordCv.put(SessionRecord.NO_READ_NUM,
					sessionRecord.noReadNum);
			number = (int) db.insert(SessionRecord.TABLENMAE, null,
					sessionRecordCv);
		}
		return number;
	}

	@Override
	public synchronized long insertMsgCont(MsgCont msgCont, MsgContExp contExp) {
		if (msgCont == null || contExp == null) {
			return -1;
		}
		int number = 0;
		SQLiteDatabase db = dbHepler.getWritableDatabase();
		if (db.isOpen()) {
			db.beginTransaction();
			ContentValues userCv = new ContentValues();
			userCv.put(MsgCont.SERVICE_CONT_ID, msgCont.serviceContId);
			userCv.put(MsgCont.FROM_ID, msgCont.fromId);
			userCv.put(MsgCont.TO_ID, msgCont.toId);
			userCv.put(MsgCont.IS_SHOW_TIME, msgCont.isShowTime);
			userCv.put(MsgCont.MSG_CONT_TYPE, msgCont.msgContType);
			userCv.put(MsgCont.READ_STATUS, msgCont.readStatus);
			userCv.put(MsgCont.REQUEST_ID, msgCont.requestId);
			userCv.put(MsgCont.SEND_STATUS, msgCont.sendStatus);
			userCv.put(MsgCont.SEND_TIME, msgCont.sendTime);
			try {
				number = (int) db.insert(MsgCont.TABLENMAE, null, userCv);
				if (number != -1) {
					Cursor cursor = db.rawQuery(
							"select last_insert_rowid() from "
									+ MsgCont.TABLENMAE, null);
					cursor.moveToFirst();
					number = cursor.getInt(cursor
							.getColumnIndex("last_insert_rowid()"));
					cursor.close();
					contExp.msgContId = number;
					ContentValues contExpCv = new ContentValues();
					contExpCv.put(MsgContExp.CONT, contExp.cont);
					contExpCv.put(MsgContExp.EXP_TYPE, contExp.expType);
					contExpCv.put(MsgContExp.MSG_CONT_ID, contExp.msgContId);
					contExpCv.put(MsgContExp.FROM_ID, contExp.fromId);
					contExpCv.put(MsgContExp.TO_ID, contExp.toId);
					number = (int) db.insert(MsgContExp.TABLENMAE, null,
							contExpCv);
					db.setTransactionSuccessful();
				}
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				db.endTransaction();
			}
		}
		return number;
	}

	@Override
	public synchronized long insertSysMsgCont(SysMsgCont sysMsgCont) {
		if (sysMsgCont == null) {
			return -1;
		}
		int number = 0;
		SQLiteDatabase db = dbHepler.getWritableDatabase();
		if (db.isOpen()) {
			ContentValues userCv = new ContentValues();
			userCv.put(SysMsgCont.SERVICE_CONT_ID, sysMsgCont.serviceContId);
			userCv.put(SysMsgCont.CONT, sysMsgCont.cont);
			userCv.put(SysMsgCont.SEND_TIME, sysMsgCont.sendTime);
			userCv.put(SysMsgCont.READ_STATUS, sysMsgCont.readStatus);
			number = (int) db.insert(SysMsgCont.TABLENMAE, null, userCv);
		}
		return number;
	}

	@Override
	public synchronized int getNoreadNum(int type, String... id) {
		int num = 0;
		SQLiteDatabase db = dbHepler.getReadableDatabase();
		if (db.isOpen()) {
			String[] columns = { "count(*) num" };
			String selection = "";
			String[] selectionArgs = id;
			Cursor cursorFile = null;
			if (type == 1) {
				selection = MsgCont.FROM_ID + "=? and " + MsgCont.READ_STATUS
						+ "=?";
				cursorFile = db.query(MsgCont.TABLENMAE, columns, selection,
						selectionArgs, null, null, null);
			} else if (type == 2) {
				selection = SysMsgCont.READ_STATUS + "=? ";
				cursorFile = db.query(SysMsgCont.TABLENMAE, columns, selection,
						selectionArgs, null, null, null);
			} else if (type == 3) {
				String[] curColumns = { "sum(noReadNum) num" };
				cursorFile = db.query(SessionRecord.TABLENMAE, curColumns,
						null, null, null, null, null);
			}

			if (cursorFile != null && cursorFile.getCount() != 0) {
				cursorFile.moveToFirst();
				num = cursorFile.getInt(cursorFile.getColumnIndex("num"));
				cursorFile.close();
			}
		}
		return num;
	}

	@Override
	public synchronized boolean updateMsgContReadStatus(int type, String... id) {
		int num = -1;
		SQLiteDatabase db = dbHepler.getWritableDatabase();
		if (db.isOpen()) {
			ContentValues cv = new ContentValues();
			String whereClause = "";
			String[] whereArgs = id;
			if (type == 1) {
				cv.put(MsgCont.READ_STATUS, 1);
				whereClause = MsgCont.FROM_ID + "=? and "
						+ MsgCont.SERVICE_CONT_ID + "<=?";
				num = db.update(MsgCont.TABLENMAE, cv, whereClause, whereArgs);
			} else if (type == 2) {
				cv.put(SysMsgCont.READ_STATUS, 1);
				whereClause = SysMsgCont.SERVICE_CONT_ID + "<=?";
				num = db.update(SysMsgCont.TABLENMAE, cv, whereClause,
						whereArgs);
			}
		}
		return num == -1 ? false : true;
	}

	@Override
	public boolean updateMsgContSendStatus(int type, String... id) {
		int num = -1;
		SQLiteDatabase db = dbHepler.getWritableDatabase();
		if (db.isOpen()) {
			ContentValues cv = new ContentValues();
			cv.put(MsgCont.SEND_STATUS, type);
			String whereClause = MsgCont.REQUEST_ID + "=?";
			String[] whereArgs = id;
			num = db.update(MsgCont.TABLENMAE, cv, whereClause, whereArgs);
		}
		return num == -1 ? false : true;
	}

	@Override
	public boolean updateMsgContServiceId(int userId, String... id) {
		int num = -1;
		SQLiteDatabase db = dbHepler.getWritableDatabase();
		if (db.isOpen()) {
			ContentValues cv = new ContentValues();
			cv.put(MsgCont.SERVICE_CONT_ID, userId);
			String whereClause = MsgCont.REQUEST_ID + "=?";
			String[] whereArgs = id;
			num = db.update(MsgCont.TABLENMAE, cv, whereClause, whereArgs);
		}
		return num == -1 ? false : true;
	}

	@Override
	public synchronized boolean updateSessionReadStatus(int num, String... id) {
		int rowNum = -1;
		SQLiteDatabase db = dbHepler.getWritableDatabase();
		if (db.isOpen()) {
			ContentValues cv = new ContentValues();
			cv.put(SessionRecord.NO_READ_NUM, num);
			String whereClause = SessionRecord.USER_ID + "=?";
			String[] whereArgs = id;
			rowNum = db.update(SessionRecord.TABLENMAE, cv, whereClause,
					whereArgs);
		}
		return rowNum == -1 ? false : true;
	}

	@Override
	public synchronized boolean updateSessionCont(String newCont,
			String newContTime, String... id) {
		int rowNum = -1;
		SQLiteDatabase db = dbHepler.getWritableDatabase();
		if (db.isOpen()) {
			ContentValues cv = new ContentValues();
			cv.put(SessionRecord.NEW_CONT, newCont);
			cv.put(SessionRecord.NEW_CONT_TIME, newContTime);
			String whereClause = SessionRecord.USER_ID + "=?";
			String[] whereArgs = id;
			rowNum = db.update(SessionRecord.TABLENMAE, cv, whereClause,
					whereArgs);
		}
		return rowNum == -1 ? false : true;
	}

	@Override
	public synchronized ArrayList<HistorySession> getHistorySessions() {
		SQLiteDatabase db = dbHepler.getReadableDatabase();
		ArrayList<HistorySession> sessionRecords = new ArrayList<HistorySession>();
		if (db.isOpen()) {
			String sql = "select s._id id, s.userId userId,s.noReadNum num,s.newCont cont,s.newContTime time,u.userName name,u.headImg headImg from session_record s left join user_temp u on s.userId = u.userId";
			Cursor cursorList = db.rawQuery(sql, null);
			while (cursorList.moveToNext()) {
				HistorySession sessionRecord = new HistorySession();
				sessionRecord.id = cursorList.getInt(cursorList
						.getColumnIndex("id"));
				sessionRecord.userId = cursorList.getInt(cursorList
						.getColumnIndex("userId"));
				sessionRecord.noReadNum = cursorList.getInt(cursorList
						.getColumnIndex("num"));
				sessionRecord.newCont = cursorList.getString(cursorList
						.getColumnIndex("cont"));
				sessionRecord.newContTime = cursorList.getString(cursorList
						.getColumnIndex("time"));
				sessionRecord.userName = cursorList.getString(cursorList
						.getColumnIndex("name"));
				sessionRecord.headImg = cursorList.getString(cursorList
						.getColumnIndex("headImg"));
				sessionRecords.add(sessionRecord);
			}
			cursorList.close();
		}
		return sessionRecords;
	}

	@Override
	public ArrayList<UserChatMsg> getUserChatMsgs(int type, String... id) {
		SQLiteDatabase db = dbHepler.getReadableDatabase();
		ArrayList<UserChatMsg> userChatMsgs = new ArrayList<UserChatMsg>();
		if (db.isOpen()) {
			String sql = "";
			switch (type) {
			case 1:
				sql = "select f._id id,f.serviceContId sContId,f.fromId fromId,f.toId toId,f.sendStatus sendStatus,f.sendTime sendTime,f.isShowTime isShowTime,f.msgContType msgContType,f.readStatus readStatus,t.cont cont,u.userName userName,u.headImg headImg  from msg_cont f left join msg_cont_exp t on f._id = t.msgContId left join user_temp u on f.fromId = u.userId where (f.fromId=? or (f.fromId=? and f.toId=?)) and f._id>? order by f._id desc limit 0,?";
				break;
			case 2:
				sql = "select f._id id,f.serviceContId sContId,f.fromId fromId,f.toId toId,f.sendStatus sendStatus,f.sendTime sendTime,f.isShowTime isShowTime,f.msgContType msgContType,f.readStatus readStatus,t.cont cont,u.userName userName,u.headImg headImg  from msg_cont f left join msg_cont_exp t on f._id = t.msgContId left join user_temp u on f.fromId = u.userId where (f.fromId=? or (f.fromId=? and f.toId=?)) and f._id<? order by f._id desc limit 0,?";
				break;
			case 3:
				sql = "select f._id id,f.serviceContId sContId,f.fromId fromId,f.toId toId,f.sendStatus sendStatus,f.sendTime sendTime,f.isShowTime isShowTime,f.msgContType msgContType,f.readStatus readStatus,t.cont cont,u.userName userName,u.headImg headImg  from msg_cont f left join msg_cont_exp t on f._id = t.msgContId left join user_temp u on f.fromId = u.userId where (f.fromId=? or (f.fromId=? and f.toId=?)) and f._id>? order by f._id asc";
				break;

			default:
				break;
			}
			String[] selectionArgs = id;
			Cursor cursorList = db.rawQuery(sql, selectionArgs);
			while (cursorList.moveToNext()) {
				UserChatMsg userChatMsg = new UserChatMsg();
				userChatMsg.id = cursorList.getInt(cursorList
						.getColumnIndex("id"));
				userChatMsg.sContId = cursorList.getInt(cursorList
						.getColumnIndex("sContId"));
				userChatMsg.fromId = cursorList.getInt(cursorList
						.getColumnIndex("fromId"));
				userChatMsg.toId = cursorList.getInt(cursorList
						.getColumnIndex("toId"));
				userChatMsg.sendStatus = cursorList.getInt(cursorList
						.getColumnIndex("sendStatus"));
				userChatMsg.sendTime = cursorList.getString(cursorList
						.getColumnIndex("sendTime"));
				userChatMsg.isShowTime = cursorList.getInt(cursorList
						.getColumnIndex("isShowTime"));
				userChatMsg.msgContType = cursorList.getInt(cursorList
						.getColumnIndex("msgContType"));
				userChatMsg.readStatus = cursorList.getInt(cursorList
						.getColumnIndex("readStatus"));
				userChatMsg.cont = cursorList.getString(cursorList
						.getColumnIndex("cont"));
				userChatMsg.userName = cursorList.getString(cursorList
						.getColumnIndex("userName"));
				userChatMsg.cont = cursorList.getString(cursorList
						.getColumnIndex("cont"));
				userChatMsg.headImg = cursorList.getString(cursorList
						.getColumnIndex("headImg"));
				userChatMsg.direct = userChatMsg.fromId == Integer
						.parseInt(ImChatManage.getInstance().getAppMarkUtil()
								.getUserId()) ? UserChatMsg.RIGHT_DIRECT
						: UserChatMsg.LEFT_DIRECT;
				userChatMsg.setLevel(userChatMsg.id);

				if (userChatMsg.userName == null) {
					userChatMsg.userName = "";
				}
				if (userChatMsg.headImg == null) {
					userChatMsg.headImg = "";
				}
				userChatMsgs.add(userChatMsg);
			}
			cursorList.close();
		}
		return userChatMsgs;
	}

	@Override
	public ArrayList<SysMsg> getSysMsgs(int type, String... id) {
		SQLiteDatabase db = dbHepler.getReadableDatabase();
		ArrayList<SysMsg> sysMsgs = new ArrayList<SysMsg>();
		if (db.isOpen()) {
			String sql = "";
			switch (type) {
			case 1:
				sql = "select s._id id,s.serviceContId sContId,s.readStatus readStatus,s.sendTime sendTime,s.cont cont,u.userId userId,u.userName userName,u.headImg headImg from sys_msg_cont s left join user_temp u on u.userId=0 where s._id>? order by s._id desc limit 0,?";
				break;
			case 2:
				sql = "select s._id id,s.serviceContId sContId,s.readStatus readStatus,s.sendTime sendTime,s.cont cont,u.userId userId,u.userName userName,u.headImg headImg from sys_msg_cont s left join user_temp u on u.userId=0 where s._id<? order by s._id desc limit 0,?";
				break;
			case 3:
				sql = "select s._id id,s.serviceContId sContId,s.readStatus readStatus,s.sendTime sendTime,s.cont cont,u.userId userId,u.userName userName,u.headImg headImg from sys_msg_cont s left join user_temp u on u.userId=0 where s._id>? order by s._id asc";
				break;

			default:
				break;
			}
			String[] selectionArgs = id;
			Cursor cursorList = db.rawQuery(sql, selectionArgs);
			while (cursorList.moveToNext()) {
				SysMsg sysMsg = new SysMsg();
				sysMsg.id = cursorList.getInt(cursorList.getColumnIndex("id"));
				sysMsg.sContId = cursorList.getInt(cursorList
						.getColumnIndex("sContId"));
				sysMsg.readStatus = cursorList.getInt(cursorList
						.getColumnIndex("readStatus"));
				sysMsg.userId = cursorList.getInt(cursorList
						.getColumnIndex("userId"));
				sysMsg.userName = cursorList.getString(cursorList
						.getColumnIndex("userName"));
				sysMsg.headImg = cursorList.getString(cursorList
						.getColumnIndex("headImg"));
				sysMsg.sendTime = cursorList.getString(cursorList
						.getColumnIndex("sendTime"));
				sysMsg.cont = cursorList.getString(cursorList
						.getColumnIndex("cont"));
				sysMsg.direct = sysMsg.userId == Integer.parseInt(ImChatManage
						.getInstance().getAppMarkUtil().getUserId()) ? UserChatMsg.RIGHT_DIRECT
						: UserChatMsg.LEFT_DIRECT;
				sysMsg.setLevel(sysMsg.id);
				sysMsg.msgContType = SysMsg.TEXT;

				if (sysMsg.userName == null) {
					sysMsg.userName = "";
				}
				if (sysMsg.headImg == null) {
					sysMsg.headImg = "";
				}
				sysMsgs.add(sysMsg);
			}
			cursorList.close();
		}
		return sysMsgs;
	}

	@Override
	public synchronized void closeDB() {
		if (dbHepler != null) {
			dbHepler.closeDB();
		}
	}

	@Override
	public boolean updateMsgContSendFailed() {
		int num = -1;
		SQLiteDatabase db = dbHepler.getWritableDatabase();
		if (db.isOpen()) {
			ContentValues cv = new ContentValues();
			cv.put(MsgCont.SEND_STATUS, 0);
			String whereClause = MsgCont.SEND_STATUS + "=?";
			String[] whereArgs = new String[] { "1" };
			num = db.update(MsgCont.TABLENMAE, cv, whereClause, whereArgs);
		}
		return num == -1 ? false : true;
	}

	@Override
	public boolean isRead(int type, String... id) {
		int status = 0;
		SQLiteDatabase db = dbHepler.getReadableDatabase();
		if (db.isOpen()) {
			switch (type) {
			case 1:
				String[] columns = { MsgCont.READ_STATUS };
				String selection = MsgCont.FROM_ID + "=? and "
						+ MsgCont.SERVICE_CONT_ID + "=?";
				String[] selectionArgs = id;
				Cursor cursorFile = null;
				cursorFile = db.query(MsgCont.TABLENMAE, columns, selection,
						selectionArgs, null, null, null);

				if (cursorFile != null && cursorFile.getCount() != 0) {
					cursorFile.moveToFirst();
					status = cursorFile.getInt(cursorFile
							.getColumnIndex(MsgCont.READ_STATUS));
					cursorFile.close();
				}
				break;
			case 2:
				String[] sysColumns = { SysMsgCont.READ_STATUS };
				String sysSelection = SysMsgCont.SERVICE_CONT_ID + "=?";
				String[] sysSelectionArgs = id;
				Cursor sysCursorFile = null;
				sysCursorFile = db.query(SysMsgCont.TABLENMAE, sysColumns,
						sysSelection, sysSelectionArgs, null, null, null);

				if (sysCursorFile != null && sysCursorFile.getCount() != 0) {
					sysCursorFile.moveToFirst();
					status = sysCursorFile.getInt(sysCursorFile
							.getColumnIndex(SysMsgCont.READ_STATUS));
					sysCursorFile.close();
				}
				break;

			default:
				break;
			}

		}
		return status == 0 ? false : true;
	}

	@Override
	public synchronized boolean updateUserInfo(UserTemp userTemp) {
		int rowNum = -1;
		SQLiteDatabase db = dbHepler.getWritableDatabase();
		if (db.isOpen()) {
			ContentValues cv = new ContentValues();
			cv.put(UserTemp.USER_NAME, userTemp.userName);
			cv.put(UserTemp.HEAD_IMG, userTemp.headImg);
			String whereClause = UserTemp.USER_ID + "=?";
			String[] whereArgs = { String.valueOf(userTemp.userId) };
			rowNum = db.update(UserTemp.TABLENMAE, cv, whereClause, whereArgs);
		}
		return rowNum == -1 ? false : true;
	}

}
